#ifndef STORAGE_CONNECTION_CONFIG_COLLECTION_HPP
#define STORAGE_CONNECTION_CONFIG_COLLECTION_HPP

#include "Storage/StorageConfig.hpp"
#include <iosfwd>
#include <string>
#include <list>

namespace Storage
{

class ConnectionConfigFactory;
class ConnectionConfig;

/// @ingroup Storage
/// @brief It manages a collection of connection configurations.
class STORAGE_API ConnectionConfigCollection
{
	typedef std::list< ConnectionConfig*> ConnectionConfigList;
public:
	typedef ConnectionConfigList::const_iterator ConstIterator;
	typedef ConnectionConfigList::iterator Iterator;


	/// @brief It initializes an empty collection.
	ConnectionConfigCollection( ConnectionConfigFactory& factory);

	/// @brief It adds the new connection configuration to the collection.
	/// @warning By adding the connection configuration to the collection, this object takes the ownership of the 
	///		objects, so the destructor will delete the object.
	void addConnectionConfig( ConnectionConfig* pNewConnConfig);

	/// @brief It removes the specified connection configuration from the collection.
	/// @warning By removing the specified connection configuration from the collection, the caller should take care of 
	///		destroying the removed object. 
	void removeConnectionConfig( ConnectionConfig* pExstingConnConfig);

	/// @brief It gets the iterator pointing to the beginning of the collection.
	/// @{
	ConstIterator begin() const { return connConfigs_.begin(); }
	Iterator begin() { return connConfigs_.begin(); }
	/// @}

	/// @brief It gets the iterator pointing to the end of the collection.
	/// @{
	ConstIterator end() const { return connConfigs_.end(); }
	Iterator end() { return connConfigs_.end(); }
	/// @}

	/// @brief It loads the connection configuration collection from the specified file.
	/// @param fileName the name of the file to load from.
 	void load( const std::string& fileName);
	/// @brief It saves the connection configuration collection from the specified file.
	/// @param fileName the name of the file to load from.
	void store( const std::string& fileName);

	void store( std::ostream& os);
	void load( std::istream& is);

	ConnectionConfigFactory& connCfgFactory() { return rConnCfgFactory_; }
	const ConnectionConfigFactory& connCfgFactory() const { return rConnCfgFactory_; }

private:
	ConnectionConfigList connConfigs_;
	ConnectionConfigFactory& rConnCfgFactory_;

private:
	/// @brief Disabled assignment operator
	ConnectionConfigCollection& operator=( const ConnectionConfigCollection&);
};

} // namespace Storage

#endif // STORAGE_CONNECTION_CONFIG_COLLECTION_HPP
